<?php
include_once("../include/init.php");
	//判断用户是否登录
	if(!isset($_SESSION['user'])){
		msg("请先登录","login.php");
		exit;
	}
$sql = "select * from tk_product";
$res = mysql_query($sql);
$info = [];
if(mysql_num_rows($res)>0){
	while($list = mysql_fetch_assoc($res)){
		$info[] =$list;
	}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>购物车页面</title>
	<link rel="stylesheet" href="../public/css/index.css" />
	<link rel="stylesheet" href="../public/css/cart.css"/>
</head>
<body>
	<!-- 头部-->
<?php
	include_once("header.php");
?>	

		<!-- 主体-->
		<div class="main">
			<div class="main_nav">
				<ul>
					<li>首页</li>
					<li class="last">购物车</li>
				</ul>
			</div>
		
			<table border=1 cellspacing=0 width="800px" rules="rows" frame="void">
		<tr height="40px">
			<th colspan=2>商品信息</th>
		
			<th>单价</th>
			<th>数量</th>
			<th>总价</th>
			<th>操作</th>
		</tr>
		<?php 
		$sum=0;
		if(isset($_SESSION['goods'])){
			foreach($_SESSION['goods'] as $vo){
				foreach($info as $v){
					if($vo['pid'] == $v['pid']){
						$price = $v['price']*$vo['num'];
						$sum+=$price;
		?>
		
		<tr height="100px"> 
			<form action="cart_edit.php" method="get">
			<input type="hidden" name="type" value="3">
			<input type="hidden" name="id" value="<?=$v['pid']?>">
			<td width="15%">
				<img src="../uploads/<?=$v['thumb']?>" width="70px" >
			</td>

			<td width="35%"><span><?= $v['pname']?></span></td>		
			<td width="10%"><span>￥<?= $v['price']?>.00</span></td>
			<td width="20%">
				<a href="cart_edit.php?type=1&id=<?=$v['pid']?>" class="change">-</a>
				<input type="text" name="num" value="<?= $vo['num']?>">
				<a href="./cart_edit.php?type=2&id=<?=$v['pid']?>" class="change">+</a>
			</td>
			<td width="10%"><span>￥<?=$price?>.00</span></td>
			<td width="10%">
				<input type="submit" name="sub" value="修改">
				<a href="./cart_did.php?did=<?=$v['pid']?>" class="del">删除</a>
			</td>
			</form>
		</tr>
		<?php }}}} ?>
		<tr height="80px">
			<td colspan=3>
				<a href=" order.php" class="pay">去付款</a>
			</td>
			<td colspan=3>
				<span class="sprice">总价:￥<?= $sum ?>.00</span>
			</td>
		</tr>
	</table>
</div>

		<div class="clearfix"></div>
			<!-- 页脚-->
			<?php
             include_once("footer.php");
             ?>
	
</body>
</html>